<template>
	<view class="container">
		<view class="top">
			<view class="left">
				<view class="balance">当前现金余额（元）</view>
				<view class="money">{{this.currentBalance}}</view>
				<navigator url="/pages/index/payments/payouts/payouts">
					<button class="payouts">提现</button>
				</navigator>
			</view>
			<view class="right">
				<view class="icome">
					<view class="accrued">
						累计收入（元）
					</view>
					<view class="cash">{{cumulativeIncome}}</view>
				</view>
				<view class="icome">
					<view class="accrued">
						累计提现（元）
					</view>
					<view class="cash">{{cumulativeWithdrawals}}</view>
				</view>
			</view>
		</view>
		<view class="details">
			<view class="subsidiary">收支明细</view>
			<view class="img">
				<uni-datetime-picker v-model="range" type="daterange" @maskClick="maskClick">
					<image src="@/static/日历.png" />日期
				</uni-datetime-picker>
			</view>
		</view>
		<view class="service">
			<uni-list>
				<uni-list :border="true" v-for="item in dillList" :key="item.id">
					<uni-list-item :title="item.name" :note="item.formatTime" :rightText="item.name == '提现' ? '-'+item.price:'+'+item.price"></uni-list-item>
				</uni-list>
			</uni-list>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dillList: [],
				range: [],
				merchantId: 1,
				cumulativeIncome:0,
				cumulativeWithdrawals:0,
				currentBalance:0,
			}
		},
		watch: {
			range(newval) {
				this.getBill()
				console.log('范围选:', this.range);
			},
			datetimerange(newval) {
				console.log('范围选:', this.datetimerange);
			}
		},
		methods: {
			maskClick(e) {
				console.log('maskClick事件:', e);
			},
			getBill() {
				uni.request({
					url: "http://localhost:8080/merchant/payouts/getbill",
					method: 'GET',
					header: {
						Authorization: "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6ImU0YzMwZWQ0LTY0YTQtNGY0Ni05ZTkyLTY4ZjBlNTA3N2Q5ZCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.dohQgAACtQJ-v4DyHhUEtX7KyB0XqIFrON7YnaPBRYEvi_0aRjCzbT_w_2cHnGxLa7xz3fWXkx51qNT94qS4iQ"
					},
					data: {
						id: this.merchantId,
						timeRange:this.range
					},
					success:(resp) => {
						this.dillList = resp.data.data
						this.getMoney(this.dillList)
					}
				})
			},
			getMoney(e){
				console.log(e.length)
				for(let i = 0; i < e.length; i++){
					if(e[i].name != "提现"){
						this.cumulativeIncome = this.cumulativeIncome + e[i].price
						console.log(this.cumulativeIncome)
					}else{
						this.cumulativeWithdrawals = this.cumulativeWithdrawals + e[i].price
						console.log(this.cumulativeWithdrawals)
					}
				}
				this.currentBalance = this.cumulativeIncome - this.cumulativeWithdrawals
			},
		},
		onLoad() {
			this.getBill()
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}

	.top {
		width: 750rpx;
		height: 300rpx;
		background-color: rgba(13, 122, 247, 1);
		position: relative;
		display: flex;
		justify-content: space-between;
	}

	.left {
		width: 350rpx;
		height: 260rpx;
		margin: 20rpx 0;

		margin-left: 15rpx;
		border-right: 1rpx solid rgba(255, 255, 255, 1);
	}

	.balance {
		width: 252rpx;
		height: 40rpx;
		font-size: 28rpx;
		font-weight: bold;
		margin-top: 30rpx;
		margin-left: 20rpx;
		line-height: 40rpx;
		color: rgba(255, 255, 255, 1);

	}

	.money {
		font-size: 36rpx;
		font-weight: bold;
		margin-left: 20rpx;
		margin-top: 30rpx;
		color: rgba(255, 255, 255, 1);
	}

	.payouts {
		width: 160rpx;
		height: 60rpx;
		line-height: 60rpx;
		margin-top: 30rpx;
		margin-left: 20rpx;
		border-radius: 8rpx;
		background-color: rgba(251, 142, 11, 1);
		color: rgba(255, 255, 255, 1);
	}

	.right {
		width: 350rpx;
		height: 260rpx;
		margin: 20rpx 0;
		margin-left: 15rpx;
	}

	.icome {
		color: rgb(255, 255, 255);
		font-size: 28rpx;
		text-align: left;
		display: flex;
		margin: 20rpx 0;

	}

	.accrued {
		width: 196rpx;
		height: 40rpx;
		font-size: 28rpx;
		font-weight: bold;
		line-height: 40rpx;
		margin-top: 30rpx;
	}

	.cash {
		font-weight: bold;
		line-height: 40rpx;
		margin-top: 30rpx;
	}

	.details {
		width: 710rpx;
		margin: 20rpx;
		display: flex;
		justify-content: space-between;
	}

	.subsidiary {
		font-size: 32rpx;
		color: rgba(16, 16, 16, 1);
		width: 240rpx;
		height: 60rpx;
	}

	.img {
		width: 120rpx;
		height: 60rpx;
		font-size: 32rpx;
		color: rgba(13, 122, 247, 1);
		vertical-align: middle;
	}

	.img image {
		width: 40rpx;
		height: 46rpx;
		margin-right: 10rpx;
		vertical-align: middle;
	}

	.service {
		width: 710rpx;
		margin: 20rpx;
	}
</style>